﻿using Basic.WxGatewayModular.Interface;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Response;
using WeDonekRpc.HttpService;
using WeDonekRpc.HttpService.Model;

namespace Basic.WxGatewayModular.Api
{
    internal class WxMerBindApi : ApiController
    {
        private readonly IMerBindService _Service;

        public WxMerBindApi (IMerBindService service)
        {
            this._Service = service;
        }

        [ApiPrower(false)]
        [ApiRouteName("/wx/bind/jump")]
        public HtmlResponse Jump ([NullValidate("wx.bind.applyId.null")] string applyId)
        {
            string uri = this._Service.GetBindUri(applyId, this.Request.ToRealUrl(), ValidateHelper.CheckIsPc(this.Request.UAgent()));
            return new HtmlResponse("<script>window.location='" + uri + "';</script>", new HttpCacheSet(HttpCacheType.NoCache));
        }

        [ApiPrower(false)]
        [ApiRouteName("/wx/bind/callback/{applyId}")]
        public RedirectResponse Callback ([NullValidate("wx.bind.applyId.null")] string applyId)
        {
            string uri = this._Service.GetCallback(applyId);
            return new RedirectResponse(uri);
        }
    }
}
